//
//  BannerViewCell.swift
//  EyeVisionForPatients
//
//  Created by PMC on 2020/3/9.
//  Copyright © 2020 tao Tao. All rights reserved.
//

import UIKit

class BannerViewCell: UICollectionViewCell {
    
    static let reuseIdentifier = "bannerViewCellId"
    
    private lazy var imageView: UIImageView = {
        let imgView = UIImageView()
        imgView.contentMode = .scaleAspectFill
        imgView.clipsToBounds = true
        return imgView
    }()
    
    var item: Int = 0
    
    var imgUrl: String? {
        didSet {
            if let url = imgUrl, url.hasPrefix("http") {
                imageView.kf.setImage(with: URL(string: url))
            } else {
                imageView.image = UIImage(named: imgUrl ?? "")
            }
        }
    }
    
    func configure(with vm: YSGBannerCellViewModel, item: Int) {
        self.item = item
        imageView.kf.setImage(with: URL(string: vm.model.content ?? ""))
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.configUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        
        configUI()
    }
    
    func configUI() {
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        contentView.addSubview(imageView)
        imageView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
    }
}
